<?php
require_once (APPLICATION_DIR."/application/model/Alumni_news.php");
require_once (APPLICATION_DIR."/application/model/Alumni_member_personal.php");
require_once (APPLICATION_DIR."/application/model/Alumni_check_cront.php");
class Cront
{
	function getInfoCheckUnsucribe($p_strCode, $p_intMemberId, $p_intNewsId)
	{
		$objCront = new DataObjects_Alumni_check_cront();
		$objCront -> selectAdd();
		$objCront -> selectAdd("*");
		$objCront -> whereAdd("mb_id=" . $p_intMemberId );
		$objCront -> whereAdd("news_id=" .$p_intNewsId );
		$objCront -> whereAdd("code='" . $p_strCode . "'");
		
		$arrTmp = $objCront -> fetchList();
		if ( count($arrTmp) )
			return true;
		else
			return false;
	}
	function insertCheckNewsletterSuccess($p_intMemberId, $p_intNewsId, $p_strCodeUnscribe)
	{
		$objCront = new DataObjects_Alumni_check_cront();
		$objCront -> mb_id = $p_intMemberId;
		$objCront -> news_id = $p_intNewsId;
		$objCront -> code = $p_strCodeUnscribe;
		$objCront -> created = date("Y-m-d H:i:s");
		
		return $objCront -> insert();
	}
	function getMemberSendNews($p_intNewsId)
	{
		$objCront = new DataObjects_Alumni_member_personal();
		$objCront -> selectAdd();
		$objCront -> selectAdd("alumni_member_personal.id, alumni_member_personal.full_name, alumni_member_contact.private_email");
		$objCront -> _join = "JOIN 		alumni_member_contact ON (alumni_member_contact.mb_id=alumni_member_personal.id 
																									AND alumni_member_contact.private_email <> '')";
		$objCront -> whereAdd("alumni_member_personal.receive_newsletter=1");
		$objCront -> whereAdd("alumni_member_personal.id not in (SELECT alumni_check_cront.mb_id 
																															FROM alumni_check_cront 
																															WHERE alumni_check_cront.news_id=$p_intNewsId 
																																		AND alumni_check_cront.mb_id=alumni_member_personal.id)");
		$objCront -> orderBy("alumni_member_personal.id ASC");
		$objCront -> limit(0,5);
		
		return $objCront -> fetchList();
	}
	function getNewestNews()
	{
		$objCront = new DataObjects_Alumni_news();
		$objCront -> selectAdd();
		$objCront -> selectAdd("*");
		$objCront -> whereAdd("newsletter=1");
		$objCront -> whereAdd("status=1");
		$objCront -> orderBy("created DESC");
		$objCront -> limit(0,1);
		
		$arrTmp = $objCront -> fetchList();
		if ( count($arrTmp) )
			return $arrTmp[0];
		else
			return false;
	}
}
?>